$(function () {
    var map = QXMap.Map('mapContainer', {
        zoom: 10,
        center: [121.3, 27.852],
        maptype: QMAP_NORMAL_MAP
    });
    map.addControl(new QXMap.LatlngControl("lnglatInfoControl", {
        position: "bottomright"
    }));
    //选择显示信息
    $(".channel").on("click", "li", function () {
        var index = $(this).index();
        if (index === 0) {
            if ($(this).html() == "显示航道") {
                // $("svg").find('.polyline').removeClass("hide")

                $("[toggle='polyline']").css("display",'block')
                $(".polyline-text").removeClass("hide")
                // $(".pointdiv").removeClass("hide")
                $(this).html("隐藏航道")
            } else {
                // $("svg").find('.polyline').addClass("hide")
                $("[toggle='polyline']").css("display",'none')
                $(".polyline-text").addClass("hide")
                // $(".pointdiv").addClass("hide")
                $(this).html("显示航道")
            }
        } else if(index===1) {
            if ($(this).html() == "隐藏港区") {
                $(".polygon-text").addClass("hide")
                $("[toggle='polygon']").css("display",'none')
                // $(".polygon-text").addClass("hide")
                // $(".pointdiv").removeClass("hide")
                $(this).html("显示港区")
            } else {
                $(".polygon-text").removeClass("hide")
                $("[toggle='polygon']").css("display",'block')
                // $(".polygon-text").removeClass("hide")
                // $(".pointdiv").addClass("hide")
                $(this).html("隐藏港区")
            }
        }else if(index===2){
            if ($(this).html() == "显示能见度") {
                visibility()
                $(this).html("隐藏能见度")
            } else {
                QXMap.removeGridMapProduct();
                QXMap.removeVectorMapProduct();
                $(this).html("显示能见度")
                $(".selectList,.colorCode").addClass("hide").removeClass("show")

            }
        }
    })
    draw();
    forecast()
    forecastChannel()
    drawchannel()

    // visibility()
    $(".rt-content").on("click", "li", function () {
        if($(this).hasClass("active"))return;
        var index = $(this).index();
        $(this).addClass("active").siblings().removeClass("active")
        if (index == 0) {
            rtThree()
        }
        else {
            rtWeek()
        }
    })
    //航道预报
    function forecastChannel() {
        $.ajax({
            type: "post",
            url: "/wzdisplay/fore/queryChannel",
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                if(!data)return
                if (data.join("")) {
                    for (var i = 0; i < data.length; i++) {
                        (function (i) {
                            var date = new Date();
                            var h = parseInt(date.getHours())-1;
                            if(!i.fore24hList.join(""))return
                            var thour=parseInt(i.fore24hList[0].time.slice(8,10));
                            h=h>thour?h:24+h;
                            h=h-thour;
                            var ar=i.fore24hList[h]
                            var html = '<div class="sign" >' +
                                '<img style="width:30px" class="icon" src="' + getImgByTimeAndWeather(ar.ww1) + '"/>' +
                                '<span>' + ar.t + '℃</span>' +
                                '</div>'
                            var html1 = htmlContentChannel(i,3);
                            var markOptionss =
                                {
                                    showlabel: false, //是否显示标签
                                    label: '', //内容
                                    htmlcontent: html, //显示HTML内容
                                    popuphtmlcontent: html1 //点击后显示的HTML内容
                                }
                            var markLabel = QXMap.PopupMarker({lng: i.lng, lat: i.lat}, markOptionss);
                            // mark=QXMap.CircleMarker({lng:i.lng,lat:i.lat},markOptions,function(){});
                            // map.addMarkerLayer(mark).$(mark).addClass("pointdiv")
                            map.addMarkerLayer(markLabel);
                            $(markLabel._icon).addClass("polyline-text hide")

                        })(data[i])
                    }
                }

            }
        })

    }
    //右侧边栏三天预报
    function rtThree() {
        $.ajax({
            type: "get",
            contentType: "application/json;charset=utf-8",
            url: "/wzdisplay/forcastRevise/queryThree",
            success: function (data) {
              if(data){
                  var html = ""
                  var arr = data.content.split(/\[|【/)
                  // var arr=data.content.split('【')

                  if (data.warning) html += "<p><span style='color: red'>警告:</span>" + data.warning + "</p>"

                  for (var i = 0; i < arr.length; i++) {
                      if (arr[i]) {
                          var ar = arr[i].split(/\]|】/)
                          // var ar=arr[i].split('】')
                          html += '<p >【' + ar[0] + '】</p>'
                          if (ar[1]) html += '<p class="txt">' + ar[1] + '</p>'
                      }
                  }
                  html += '<p class="publishTime">' + data.time + '</p>'
                  $(".rtContent").html(html)
              }

            }
        })
    }
    rtThree()
    function rtWeek() {
        $.ajax({
            type: "get",
            contentType: "application/json;charset=utf-8",
            url: "/wzdisplay/forcastRevise/queryWeek",
            success: function (data) {
                if(data){
                    var content=data.content;
                    var arr=[];
                    console.log(content.indexOf("<br/>"))
                    if(content.indexOf("<br/>")!=-1){
                        arr = content.split("<br/>")
                    }else{
                        arr = content.split("<br>")
                    }
                    var html = "";
                    // var ar=arr[0].split("：");
                    var ar = arr[0].split(/：|\:/);
                    var arr1 = arr[1].split(/\(|（/)
                    html += "<p>" + ar[0] + "：</p>" +
                        '<p class="txt">' + ar[1] + "</p>" +
                        '<p>' + arr1[0] + "：</p>"

                    for (var i = 1; i < arr1.length; i++) {
                        html += '<p class="txt">（' + arr1[i] + '</p>'
                    }
                    html += '<p class="publishTime">' + data.time + '</p>'
                    $(".rtContent").html(html)
                }
            }
        })
    }
    // rtWeek()
    //港区的预报
    function forecast() {
        $.ajax({
            type: "post",
            url: "/wzdisplay/fore/queryPort",
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    (function (i) {
                        var date = new Date();
                        var h = parseInt(date.getHours())+1;

                        var obj=null;
                        if(!i.fore24hList.join(""))return
                        var thour=parseInt(i.fore24hList[0].time.slice(8,10));
                            h=h>thour?h:24+h;
                            h=h-thour;
                            console.log(h)
                       var ar=i.fore24hList[24-h]
                        var html = '<div class="sign" >' +
                            '<img style="width:30px" class="icon" src="' + getImgByTimeAndWeather(ar.ww1) + '"/>' +
                            '<span>' + ar.t + '℃</span>' +
                            '</div>'
                        var html1 = htmlContent(i,7);
                        var markOptionss =
                            {
                                showlabel: false, //是否显示标签
                                label: '', //内容
                                htmlcontent: html, //显示HTML内容
                                popuphtmlcontent: html1 //点击后显示的HTML内容
                            }
                        var markLabel = QXMap.PopupMarker({lng: i.lng, lat: i.lat}, markOptionss);
                        map.addMarkerLayer(markLabel);
                        $(markLabel._icon).attr("toggle","polygon")
                        // $(mark.label._container).addClass("polygon");
                        $(mark.label._container).attr("toggle","polygon");
                    })(data[i])
                }
                changeThreeToSeven(data)

            }
        })

    }
    //航道预报内容
    function htmlContentChannel(points,day) {
        var html = "";
        html += '<div class="ftWeather"><h2>' + points.name + '天气预报</h2>' +
            '<div>' +
            '<ul class="ftNav">' +
            '<li class="active">24小时</li>' +
            '<li>'+day+'天</li>' +
            '</ul>' +
            '<b class="rt timeUpdate">' + timeToTime(points.fore24hList[0].time) + '</b>' +
            '<div class="clear"></div>' +
            '</div><div class="ftTable">'
        html += tableContentOne(points.fore24hList)
        html += tableContentSeven(points.fore3dList);

        html += '</div></div>'
        return html
    }
    //港口预报内容
    function htmlContent(points,day) {
        var html = "";
        html += '<div class="ftWeather"><h2>' + points.name + '天气预报</h2>' +
            '<div>' +
            '<ul class="ftNav">' +
            '<li class="active">24小时</li>' +
            '<li>'+day+'天</li>' +
            '</ul>' +
            '<b class="rt timeUpdate">' + timeToTime(points.fore24hList[0].time) + '</b>' +
            '<div class="clear"></div>' +
            '</div><div class="ftTable">'
        html += tableContentOne(points.fore24hList)
        html += tableContentSeven(points.fore7dList);

        html += '</div></div>'
        return html
    }
    function tableContentOne(list) {
        var h = parseInt(list[0].time.slice(8, 10));
        var n = 0;
        var html = "";
        html += '<table  class=" ftData">' +
            '<thead>' +
            '<tr><th style="width: 70px">时间</th>'
         for (var i = list.length-1,j=0; i >=0,j<list.length;j++, i--) {
            html += '<th>' + ((j + h) > 23 ? n++ : (j + h)) + '时</th>'
        }
        html += ' </tr>' +
            '</thead>' +
            '<tbody>' +
            '<tr><td class="active">' +
            '风力风向 <br>' +
            '(单位:级)' +
            '</td>'
         for (var i = list.length-1; i >=0; i--) {
            html += '<td><i>' + winddFormat(list[i].windd) + '</i>'

            html += '<b class="seven">' + list[i].winds + '</b></td>'


        }
        html += '</tr>' +
            '<tr>' +
            '<td class="active">天气</td>'
         for (var i = list.length-1; i >=0; i--) {
            html += '<td>' +
                '<img class="icon" src="' + getImgByTimeAndWeather(list[i].ww1) + '"/>'


            '</td>'
        }
        html += ' </tr>' +
            '<tr>' +
            '<td class="active"> 气温<br> (单位：℃)</td>'
         for (var i = list.length-1; i >=0; i--) {
            html += '<td>' +
                '<span>' + list[i].t + '</span>' +
                '</td>'
        }
        html += ' </tr>' +
            '<tr>' +
            '<td class="active">降雨<br>(单位:mm)</td>'
         for (var i = list.length-1; i >=0; i--) {
            html += '<td><span>' + list[i].pr01 + '</span></td>'
        }
        html += '</tr>' +


            '</tbody>' +
            '</table>'
        return html
    }
    function tableContentSeven(list) {
        var html = "";
        html += '<table style="width:100%" class="hide ftData">' +
            '<thead>' +
            '<tr><th  style="width: 70px">时间</th>'
         for (var i =0; i<list.length; i++) {
            html += '<th>' + (i+ 1) + '天</th>'
        }
        html += ' </tr>' +
            '</thead>' +
            '<tbody>' +
            '<tr><td class="active">' +
            '风力风向 <br>' +
            '(单位:级)' +
            '</td>'
        for (var i =0; i<list.length; i++)  {
            html += '<td><i>' + winddFormat(list[i].windd) + '</i>'

            html += '<b class="seven">' + list[i].winds + '</b></td>'


        }
        html += '</tr>' +
            '<tr>' +
            '<td class="active">天气</td>'
        for (var i =0; i<list.length; i++)  {
            html += '<td>' +
                '<img class="icon" src="' + getImgByTimeAndWeather(list[i].ww1) + '"/>'

            '</td>'
        }
        html += ' </tr>' +
            '<tr>' +
            '<td class="active"> 气温<br> (单位：℃)</td>'
        for (var i =0; i<list.length; i++)  {
            html += '<td>' +
                '<span>' + list[i].t + '</span>' +
                '</td>'
        }
        html += ' </tr>' +
            '<tr>' +
            '<td class="active">降雨<br>(单位:mm)</td>'
        for (var i =0; i<list.length; i++)  {
            html += '<td><span>' + list[i].pr24 + '</span></td>'
        }

        html += '</tr>' +

            '</tbody>' +
            '</table>'
        return html
    }
    //切换显示时间的数据
    function changeThreeToSeven(data) {
        $("#main").unbind()
        $("#main").on("click", ".ftNav li", function () {
            var index = $(this).index()
            if (index == 0) {
                var str = timeToTime(data[0].fore24hList[0].time)
                $(".timeUpdate").html(str)
            } else {
                var str = timeToTime(data[0].fore7dList[0].time?data[0].fore7dList[0].time:data[0].fore7dList[1].time)
                $(".timeUpdate").html(str)
            }

            $(this).addClass("active").siblings('.active').removeClass("active")
            $(".ftData").eq(index).removeClass("hide").siblings("table").addClass("hide")
        })
    }
    // changeThreeToSeven()
    //绘制港区 
    function draw() {
        var polygonOptions =
            {
                color: '#0033ff',
                weight: 3,
                fillColor: '#83AEFF',
                opacity: .3,
                fillopacity: 0,
                isfill: true
            }
        var changNan = {
            name: "苍南港区",
            center: {lng: 120.662, lat: 27.503},
            points: "120.645762,27.491951,120.649499,27.498617,120.666747,27.497079,120.68112,27.492977,120.684282,27.501949,120.664447,27.507589,120.64835,27.506307,120.642313,27.499642"
        }

        var pingyang = {
            name: "平阳港区",
            center: {lng: 120.611, lat: 27.596},
            points: "120.600919,27.602132,120.60135,27.591759,120.618454,27.582026,120.622047,27.59765"
        }

        var rui = {
            name: "瑞安港区",
            center: {lng: 120.665, lat: 27.736},
            points: "120.624419,27.758819,120.68651,27.702031,120.704619,27.72301,120.645116,27.769559"
        }
        var jiang = {
            name: "瓯江港区",
            center: {lng: 120.886, lat: 27.987},
            points: "120.77,27.98,120.90,28.01,121.00,27.93,120.85,27.97"
        }
        var daxiao = {
            name: "大小门岛港区",
            center: {lng: 121.080, lat: 27.977},
            points: "121.053306,27.951214,121.048706,27.991029,121.082472,28.017414,121.09742,28.008229,121.086651,27.985415,121.160085,27.964336,121.156061,27.956679,121.101599,27.945597"
        }
        var leqing = {
            name: "乐清湾港区",
            center: {lng: 121.012, lat: 28.149},
            points: "120.95,27.98,121.07,28.13,121.13,28.26,120.97,28.15"
        }
        var zhuangy = {
            name: "状元岙港区",
            center: {lng: 121.096, lat: 27.882},
            points: "121.044107,27.881756,121.16139,27.910362,121.133794,27.879202,121.074578,27.849055"
        }
        drawpolygon(changNan, polygonOptions)
        drawpolygon(pingyang, polygonOptions)
        drawpolygon(rui, polygonOptions)
        drawpolygon(jiang, polygonOptions)
        drawpolygon(daxiao, polygonOptions)
        drawpolygon(leqing, polygonOptions)
        drawpolygon(zhuangy, polygonOptions)
    }
    //绘制多边形
    function drawpolygon(str, polygonOptions) {
        var arr = str.points.split(",");
        var psts = [];
        for (var i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                psts.push({lng: arr[i], lat: arr[i + 1]})
            }
        }


        var polyline = QXMap.Polygon(psts, polygonOptions, function () {
        });
        // $(mark.label._container).addClass("pointdiv hide")

        map.addVectorLayer(polyline)
        // $(polyline._container).addClass("polygon");
        $(polyline._container).attr("toggle","polygon");
        //绘制多边形中心点
        var markOptions =
            {
                showlabel: true,
                radius: 3,
                direction: "right",
                color: 'red',
                content: str.name,
                fillColor: 'red',
                textColor: "red"
            }
        mark = QXMap.CircleMarker(str.center, markOptions, function () {
            // $(".polygon-point").unbind()
        });
        map.addMarkerLayer(mark)

        // $(mark._container).addClass("polygon")
        // $(mark._container).attr("toggle","polygon")
        $(mark._container).attr("toggle","polygon")
        $(mark.label._container).addClass("polygon-text");
    }
    //绘制航线
    function drawchannel() {
        var luxiToDamen = {
            name: "鹿西岛至大门岛",
            center: {lng: 121.162, lat: 28.00},
            points: [{lng: 121.226145, lat: 27.990442}, {lng: 121.10285, lat: 27.987799}]
        }

        var luxiToDongtou = {
            name: "鹿西岛至洞头本岛",
            center: {lng: 121.192, lat: 27.907},
            points: [{lng: 121.226145, lat: 27.990442}, {lng: 121.170905, lat: 27.823867}]
        }

        var ruianToBeidao = {
            name: "瑞安至北麂岛",
            center: {lng: 120.950, lat: 27.690},
            points: [{lng: 120.655545, lat: 27.750708}, {lng: 121.216657, lat: 27.631206}]
        }

        var ruianToNandao = {
            name: "瑞安至南麂岛",
            center: {lng: 120.838, lat: 27.639},
            points: [{lng: 120.655545, lat: 27.750708}, {lng: 121.084864, lat: 27.471669}]
        }

        var aoToNandao = {
            name: "鳌江至南麂岛",
            center: {lng: 120.799, lat: 27.537},
            points: [{lng: 120.564605, lat: 27.590765}, {lng: 121.084864, lat: 27.471669}]
        }
        addPolyline(luxiToDamen, "green", .8)
        addPolyline(luxiToDongtou, "green", .8)
        addPolyline(ruianToBeidao, "green", .8)
        addPolyline(ruianToNandao, "green", .8)
        addPolyline(aoToNandao, "green", .8)
    }
    //地图多线段封装
    //points点的集合，fillColor线的颜色
    function addPolyline(points, fillColor, opacity) {
        var polylineOptions =
            {
                color: fillColor,
                weight: 10,
                fillColor: fillColor,
                opacity: opacity,
                fillopacity: 0.8,
                isfill: true
            }
        var polyline = QXMap.PolyLine(points.points, polylineOptions, function () {

        });
        //var xy=map.getPixelFromLonLat(points.center);
        map.addMarkerLayer(polyline);
        // $(polyline._container).addClass("polyline hide");
        $(polyline._container).attr("toggle","polyline").css("display","none");
        //绘制航道中心点
        var markOptions =
            {
                showlabel: true,
                radius: 3,
                direction: "right",
                color: 'red',
                content: points.name,
                fillColor: 'red'
            }
        mark = QXMap.CircleMarker(points.center, markOptions, function () {
        });
        map.addMarkerLayer(mark)
        // $(mark.label._container).addClass("polyline-text hide");
        $(mark.label._container).addClass("polyline-text hide");
        // $(mark._container).addClass("polyline-text hide");
        $(mark._container).attr('toggle',"polyline").css('display','none');
    };
    //能见度预报
    function visibility() {
        var time=oneTime()
        var url='http://10.135.30.116:8080/ZJDataCenter/api/NAFP_FOR_FTM_ZJWARRS/getContourEleValidtimeListByTime?userid=zjwlzx&pwd=123&productcategory=vis&fcstlevel=2001&time='+time+'&timetype=D&admincodes=330000&elements=time,hours&limitcnt=100&dataformat=json'
        $.ajax({
            type:'get',
            url:url,
            success:function(data) {
                console.log(data)
                if (data.returnCode == 0) {
                    $(".selectList").addClass('show').removeClass("hide")
                    visiForcast(data.DS[0].time,data.DS[0].hours)
                    loadVist(data.DS)
                    loadVistHours(data.DS);
                    changeVisiTime()
                    changeVisiHour()
                }
            }
        })

    }
    function visiForcast(time,hour){
        QXMap.removeGridMapProduct();
        QXMap.removeVectorMapProduct();
        console.log(time,hour)
        var mapProductOptions = {
            productcategory: 'vis',
            time: time,
            regioncode: '330000',
            method: 'NAFP_FOR_FTM_ZJWARRS',
            interface: 'getContourEleByTimeAndRegionCode',
            key: 'zjwlzx',
            pwd: '123',
            level: 2001,
            gridmethod: 'NAFP_FOR_FTM_ZJWARRS',
            gridinterface: 'getGridForecastEleGridInRectByTimeAndLevelAndValidtime',
            nlat: 32,
            slat: 22,
            wlon: 116,
            elon: 124,
            validtime: hour,
            isshowzero: false,
            isshowcontrol: true,
            position: "topright"
        }
        var product = QXMap.addVectorMapProduct(mapProductOptions, function (data) {
            var da = data._data;
            var r = [];
           if(da.length>0){
               for (var i = 0; i < da.length; i++) {
                   for (var j = i + 1; j < da.length; j++)
                       if (da[i].color === da[j].color) j = ++i;
                   r.push(da[i]);
               }
               addWindColorCode("能见度", r, "m")
               $(".colorCode").removeClass('hide').addClass("show")
           }
            if (data == null) return;
            //QXMap.showValueClassByType(36.0);
        });

    }
    //获得当前的时间
    function oneTime() {
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth() + 1;
        // date.setDate(date.getDate()-1)
        date.setHours(date.getHours() - 1)
        var hour = date.getHours();

        hour = hour > 9 ? hour : '0' + hour;
        month = month > 9 ? month : '0' + month;
        day = day > 9 ? day : '0' + day;
        return date.getFullYear() + '' + month + '' + day + '' + hour + "0000"
    }
    function winddFormat(windd) {
        var w = parseFloat(windd);
        if (bettween(w, 22.5, 67.5)) {
            return "东北风";
        } else if (bettween(w, 67.5, 112.5)) {
            return "东风";
        } else if (bettween(w, 112.5, 157.5)) {
            return "东南风";
        } else if (bettween(w, 157.5, 202.5)) {
            return "南风";
        } else if (bettween(w, 202.5, 247.5)) {
            return "西南风";
        } else if (bettween(w, 247.5, 292.5)) {
            return "西风";
        } else if (bettween(w, 292.5, 337.5)) {
            return "西北风";
        } else if (bettween(w, 337.5, 360) || bettween(w, 0, 22.5)) {
            return "北风";
        }
        return null;
    }
    function getImgByTimeAndWeather(WW3) {

        switch (parseInt(WW3)) {
            case 1: {
                return "/wzdisplay/assets/imgs/rain/icon_1.png";
                break;
            }
            case 2: {
                return "/wzdisplay/assets/imgs/rain/icon_3.png";
                break;
            }
            case 3: {
                return "/wzdisplay/assets/imgs/rain/icon_4.png";
                break;
            }
            case 4: {
                return "/wzdisplay/assets/imgs/rain/icon_4.png";
                break;
            }
            case 5: {
                return "/wzdisplay/assets/imgs/rain/icon_5.png";
                break;
            }
            case 6: {
                return "/wzdisplay/assets/imgs/rain/icon_6.png";
                break;
            }
            case 7: {
                return "/wzdisplay/assets/imgs/rain/icon_7.png";
                break;
            }
            case 8: {
                return "/wzdisplay/assets/imgs/rain/icon_8.png";
                break;
            }
            case 9: {
                return "/wzdisplay/assets/imgs/rain/icon_9.png";
                break;
            }
            case 10: {
                return "/wzdisplay/assets/imgs/rain/icon_10.png";
                break;
            }
            case 11: {
                return "/wzdisplay/assets/imgs/rain/icon_11.png";
                break;
            }
            case 12: {
                return "/wzdisplay/assets/imgs/rain/icon_12.png";
                break;
            }
            case 13: {
                return "/wzdisplay/assets/imgs/rain/icon_13.png";
                break;
            }
            case 14: {
                return "/wzdisplay/assets/imgs/rain/icon_14.png";
                break;
            }
            case 15: {
                return "/wzdisplay/assets/imgs/rain/icon_15.png";
                break;
            }
            case 16: {
                return "/wzdisplay/assets/imgs/rain/icon_16.png";
                break;
            }
            case 17: {
                return "/wzdisplay/assets/imgs/rain/icon_17.png";
                break;
            }
            case 18: {
                return "/wzdisplay/assets/imgs/rain/icon_18.png";
                break;
            }
            case 19: {
                return "/wzdisplay/assets/imgs/rain/icon_19.png";
                break;
            }
            case 20: {
                return "/wzdisplay/assets/imgs/rain/icon_20.png";
                break;
            }
            case 21: {
                return "/wzdisplay/assets/imgs/rain/icon_21.png";
                break;
            }
            case 22: {
                return "/wzdisplay/assets/imgs/rain/icon_22.png";
                break;
            }
            case 23: {
                return "/wzdisplay/assets/imgs/rain/icon_23.png";
                break;
            }
            case 24: {
                return "/wzdisplay/assets/imgs/rain/icon_24.png";
                break;
            }
            case 25: {
                return "/wzdisplay/assets/imgs/rain/icon_25.png";
                break;
            }
            case 26: {
                return "/wzdisplay/assets/imgs/rain/icon_26.png";
                break;
            }
            case 27: {
                return "/wzdisplay/assets/imgs/rain/icon_27.png";
            }
            case 28: {
                return "/wzdisplay/assets/imgs/rain/icon_28.png";
            }
            case 29: {
                return "/wzdisplay/assets/imgs/rain/icon_29.png";
            }
            case 30: {
                return "/wzdisplay/assets/imgs/rain/icon_30.png";
            }
            case 31: {
                return "/wzdisplay/assets/imgs/rain/icon_31.png";
            }
            case 32: {
                return "/wzdisplay/assets/imgs/rain/icon_32.png";
            }
            case 33: {
                return "/wzdisplay/assets/imgs/rain/icon_33.png";
            }
            case 53: {
                return "/wzdisplay/assets/imgs/rain/icon_53.png";
            }
            default : {
                return "/wzdisplay/assets/imgs/rain/icon_1.png";
            }
        }
    }
    function timeToTime(time) {
        var three = time
        var tyear = three.slice(0, 4)
        var tmonth = three.slice(4, 6)
        var tday = three.slice(6, 8)
        var thour = three.slice(8, 10)
        var tmin = three.slice(10, 12)
        return tyear + "/" + tmonth + "/" + tday + " " + thour + ":" + tmin + "更新";
    }
    function bettween(windd, l, h) {
        if (l <= windd && windd < h) return true;
        else return false;
    }
    //分割能见度的发布时间
    function getTime(str){
        var year=str.slice(0,4);
        var month=str.slice(4,6);
        var day=str.slice(6,8);
        var hour=str.slice(8,10);
        return year+'/'+month+"/"+day+"  "+hour+":00"
    }
    //发布能见度的时间添加到页面
    function loadVist(da){
        var r = [];//存放时间
        var html='';
        for (var i = 0; i < da.length; i++) {
            for (var j = i + 1; j < da.length; j++)
                if (da[i].time === da[j].time) j = ++i;
            r.push(da[i]);
        }

        for(var i=0;i<r.length-1;i++){
            for(var j=0;j<r.length-1-i;j++){
                if(r[j].time <r[j+1].time){
                    var  temp = r[j];
                    r[j] = r[j+1];
                    r[j+1] = temp;
                }
            }
        }
        r.forEach(function(val){
            html+='<li time="'+val.time+'">'+getTime(val.time)+'发布'+'</li>'
        })
        $("#visi ul").html(html)
        $("#visi p").html('<span time="'+r[0].time+'">'+getTime(r[0].time)+'发布</span><b></b>')
    }
    //发布能见段的时间段
    function loadVistHours(da){
        var r = [];//存放时间
        var html='';
        for (var i = 0; i < da.length; i++) {
            for (var j = i + 1; j < da.length; j++)
                if (da[i].hours === da[j].hours) j = ++i;
            r.push(da[i]);
        }
        r.forEach(function(val){
            html+='<li hours="'+val.hours+'">'+val.hours+'小时预报</li>'
        })
        $("#visi-sub ul").html(html)
        $("#visi-sub p span").html(r[0].hours+'小时预报')
    }
    //切换能见度的时间
    function changeVisiTime(){
        $("#visi").unbind();
        $("#visi").mouseenter(function(){
            $(this).find(".rain-cn").addClass("show").removeClass("hide")
        })
        $("#visi").on("click","li",function(){
            var time = $(this).attr("time");
            var html=$(this).html();
            $(this).parent().parent().addClass("hide").removeClass("show")
            $('#visi p').html('<span time="'+time+'">'+html+'</span> <b></b>')
            $("#visi-sub p span").html('0小时预报')
            visiForcast(time,0)

        })
    }
    //切换能见的时间段
    function changeVisiHour(){
        $("#visi-sub").unbind();
        $("#visi-sub").mouseenter(function(){
            $(this).find(".rain-cn").addClass("show").removeClass("hide")
        })
        $("#visi-sub").on("click","li",function(){
            var hour= $(this).attr("hours");
            var time=$("#visi").find("span").attr("time")
            visiForcast(time,hour)
            $(this).parent().parent().addClass("hide").removeClass("show")
            $('#visi-sub p').html('<span >'+$(this).html()+'</span> <b></b>')

        })

    }
    //能见度的色标
    function addWindColorCode(title, colorCode, U) {
        var html = ' <p>' + title + '</p><ul>'
        if (colorCode.join("")) {
            for (var i = 0; i < colorCode.length; i++) {
                // var r = colorCode[i].color.lastIndexOf(",")

                html += '<li style="width:65px">' +
                    '<span  style="background: rgb(' + colorCode[i].color+ ')"></span>' +
                    '<span>' + colorCode[i].value + U + '</span>' +
                    '</li>'
            }
            html += "</ul>"
            $(".colorCode").html(html)
        }
    }



})